
const app = getApp()

Page({
  data: {
    faceUrl: "../resource/images/noneface.png",
  },

  onLoad: function (params) {
    
  },

  followMe: function (e) {
    
  },
  logout: function () {
    var user=app.userInfo;
    wx.request({
      url: app.serverURL + '/logout?userId='+user.id,
      method: 'post',
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        wx.hideLoading();
        if (res.data.status == 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'success',
            duration: 3000
          });
          app.userInfo = null;
          wx.navigateTo({
            url: '../userLogin/login',
          });
        } else if (res.statusCode == 500) {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 3000
          });
        }
      }
    })
    
  },

  changeFace: function () {
    var that=this;
    wx.chooseImage({
      count: 1,
      sizeType: [ 'compressed'],
      sourceType: ['album'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths);
        wx.uploadFile({
          url: app.serverURL +"/uploadFace?userId="+app.userInfo.id, // 仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          success(res) {
            console.log(res);
            that.setData({
              faceUrl: app.serverURL+JSON.parse(res.data).data
            });
            wx.showToast({
              title: JSON.parse(res.data).msg,
              icon: 'success'
            })
          }
        })
      }
    })
  },

  uploadVideo: function () {
   
  },


  doSelectWork: function () {
   
  },

  doSelectLike: function () {
   
  }

})
